#include<iostream>//uncle-lu
#include<fstream>
#include<map>
#include<utility>
#include<string>

std::map<std::pair<std::string, std::string>, int>table;

bool left = false;
std::string sum;

void mix(std::string line)
{
	sum = sum + line;
	return ;
}

void func_mix(std::string temp)
{
	std::pair<std::string, std::string>t = std::make_pair(sum, temp);
	if(table.find(t) != table.end())
		table[t]++;
	else
		table[t]=1;


	left = false;
	sum.clear();
	return ;
}

void func(std::string line)
{
	if(line[0] == '[')
	{
		left = true;
		line = line.substr(1, line.length());
	}

	std::string temp;

	for(auto it = line.end()-1; it != line.begin(); it--)
	{
		if(left && *it == ']')
		{
			func( line.substr(0, it - line.begin()) );
			func_mix( line.substr(it - line.begin() + 1, line.length()) );
			return ;
		}
		
		if(*it == '/')
		{
			temp = line.substr(it - line.begin() + 1, line.length());
			line = line.substr(0, it - line.begin());
			break;
		}
	}

	std::pair<std::string, std::string>t = std::make_pair(line, temp);
	if(table.find(t) != table.end())
		table[t]++;
	else
		table[t]=1;

	if(left)mix(line);

	return ;
}

int main()
{
	std::ifstream in;
	std::string line;

	in.open("./199801.txt");
	while(in >> line)
	{
		func(line);
	}
	in.close();

	std::ofstream out;
	out.open("./out.txt");

	out << "Word\t" << "Char\t" << "Cnt\n";
	for(auto it = table.begin(); it != table.end(); it++)
	{
		out << (it->first).first << "\t" << (it->first).second << "\t" << it->second << "\n";
	}

	out.close();

	return 0;
}
